﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JavaDevToys.Rcl.Utils
{
    public class GuidHelper
    {
        /// <summary>
        /// 生成19位数字GUID
        /// </summary>
        /// <returns></returns>
        public static long Generate19DigitGuid()
        {
            Guid guid = Guid.NewGuid();
            byte[] guidBytes = guid.ToByteArray();

            ulong part1 = BitConverter.ToUInt64(guidBytes, 0);

            long guid19Digits = long.Parse(string.Format("{0:D19}", part1));
            return guid19Digits;
        }
        /// <summary>
        /// 按时间生成19位数字
        /// </summary>
        /// <returns></returns>
        public static long GenerateUnique19DigitId()
        {
            long timestamp = DateTime.Now.Ticks;

            int randomPart = new Random().Next(0, 9);

            long uniqueId = long.Parse(string.Format("{0:D18}{1:D1}", timestamp, randomPart));
            return uniqueId;
        }
    }
}
